package com.kfirszt.elearning.persistence.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.kfirszt.elearning.dictionary.QuestionType;
import com.kfirszt.elearning.utils.QuizUtils;

@Entity
@Table(name = "question")
public class Question extends BaseEntity {

	private static final long serialVersionUID = 1L;
	
	@Column(name = "content")
	private String content;
	
	@Column(name = "question_type")
	@Enumerated(EnumType.STRING)
	private QuestionType questionType;
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "question_answer", joinColumns = {@JoinColumn(name = "quiestion_id")}, inverseJoinColumns ={@JoinColumn(name = "answer_id")})
	private List<Answer> answers = new ArrayList<Answer>();

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public QuestionType getQuestionType() {
		return questionType;
	}

	public void setQuestionType(QuestionType questionType) {
		this.questionType = questionType;
	}

	public List<Answer> getAnswers() {
		return answers;
	}

	public void setAnswers(List<Answer> answers) {
		this.answers = answers;
	}
	
	public String getHTMLAnswers(){
		return QuizUtils.convertToHTML(answers, questionType);
	}

}
